import request from "@Utils/webServerRequest"
import dyrequest from "@Utils/request"

const MARKETING = "marketing/"
const PRODUCT = "product/"
const SHOP = "shop/"
const BYTESHOP = "byteshop/"
const ECCOMMARKETSHOP = "ecom_market_shop"
// 商品列表
export const getProdectList = (data) => {
  return dyrequest({
    url: `${PRODUCT}tproduct/list`,
    method: "get",
    paramete: data,
    timeout: 5000
  })
}
/**
 *
 * @param {product_id:商品ID} data
 * @returns
 */
// 商品详情
export const getPreviewDetail = (data) => {
  if (!data.product_id) throw new Error("商品 product_id 不能为空")
  return dyrequest({
    url: `${PRODUCT}tproduct/previewDetail`,
    method: "get",
    paramete: {
      need_conv_pkg: false, // 是否需要转换PKG
      product_id: data.product_id,
      use_std_brand: true
    }
  })
}
// 优惠券列表
export const getCouponList = (data) => {
  const getData = {
    start_apply_time: data.start_apply_time || '',
    end_apply_time: data.end_apply_time || '',
    // coupon_biz_type: data.coupon_biz_type || '',
    coupon_info: data.coupon_info || '',
    coupon_type_group: data.coupon_type_group || 1, // 优惠券类型==》 0：全部 1：通用优惠券 2：涨粉券 3：达人专属 4：店铺新人
    favoured_type: data.favoured_type || 0, //优惠方式==》 0：全部 21：全店通用-折扣 22：全店通用-立减 23：全店通用-满减 41：指定商品-折扣 42：指定商品-立减 43：指定商品-满减
    status: data.status || 3, // 优惠券状态==》0：全部 2：已作废 3：生效中 4：过期
    page: data.page || 1,
    size: data.pageSize || data.page_size || data.size || 100,
    sort_by_stock: data.sort_by_stock || false, // 排序开关无用
    _bid: data._bid || ECCOMMARKETSHOP
  }
  Object.keys(getData).forEach(key => {
    if (!getData[key]) delete getData[key]
  })
  return dyrequest({
    url: `${MARKETING}coupons/v1/list`,
    method: "get",
    paramete: getData
  })
}
// 优惠券详情
export const getCouponDetails = (data) => {
  if (!data.coupon_meta_id) throw new Error("优惠券 coupon_meta_id 不能为空")
  return dyrequest({
    url: `${MARKETING}coupons/v1/shopcoupons/${data.coupon_meta_id}`,
    method: "get",
    paramete: {
      _bid: data._bid || ECCOMMARKETSHOP
    }
  })
}

// 惊喜券列表
export const getSurpriseTicketList = (data) => {
  return dyrequest({
    url: `${MARKETING}precision_promotion/v1/get_precision_promotion_instances`,
    method: "get",
    paramete: {
      page: data.page || 1,
      page_size: data.size || data.page_size || data.pageSize || 20,
      biz_groups: "1&biz_groups=2&biz_groups=3&biz_groups=4", // 类型 1新人群  2 老客人群 3流失人群 4 其他人群 获取全部 上传4个
      _bid: data._bid || ECCOMMARKETSHOP,
      status: data.status || 3 // 优惠券状态==》5：已作废 3：生效中 4:已经过期
    }
  })
}

// 惊喜券详情
export const getSurpriseTicketDetails = (data) => {
  if (!data.activity_id) throw new Error("优惠券 activity_id 不能为空")
  return dyrequest({
    url: `${MARKETING}precision_promotion/v1/get_precision_promotion_instance`,
    method: "get",
    paramete: {
      activity_id: data.activity_id,
      _bid: data._bid || ECCOMMARKETSHOP,
      //   status: data.status || 3 // 优惠券状态==》5：已作废 3：生效中 4:已经过期
    }
  })
}


// 获取满减活动列表 24/4/30新增跨品多件优惠
export const getFullDiscountActivity = (data) => {
  return dyrequest({
    url: `${MARKETING}activity/v1/query_full_discount_activity`,
    method: "get",
    paramete: {
      activity_status: data.activity_status || 2, // 0 全部 1未开始 2进行中 3已结束 4已失效
      page: data.page || 1,
      pageSize: data.pageSize || data.page_size || data.size || 20,
      _bid: data._bid || ECCOMMARKETSHOP
      //   status: data.status || 3 // 优惠券状态==》5：已作废 3：生效中 4:已经过期
    }
  })
}

// 获取同品多件优惠
export const getFullDiscountOnePriductActivity = (data) => {
  return dyrequest({
    url: `${MARKETING}activity/v1/query_multi_piece_discount_activity`,
    method: "get",
    paramete: {
      activity_status: data.activity_status || 2, // 0 全部 1未开始 2进行中 3已结束 4已失效
      page: data.page || 1,
      pageSize: data.pageSize || data.page_size || data.size || 20,
      _bid: data._bid || ECCOMMARKETSHOP
      //   status: data.status || 3 // 优惠券状态==》5：已作废 3：生效中 4:已经过期
    }
  })
}
// 获取满减活动详情
export const getFullDiscountActivityDetails = (data) => {
  if (!data.activity_id) throw new Error("缺少活动ID")
  return dyrequest({
    url: `${MARKETING}activity/v1/get_full_discount_activity`,
    method: "get",
    paramete: {
      activity_id: data.activity_id,
      _bid: data._bid || ECCOMMARKETSHOP,
      status: data.status || 3 // 优惠券状态==》5：已作废 3：生效中 4:已经过期
    }
  })
}

// 获取可以参加活动的商品列表 POST V2 惊喜券在其他接口 === 新人券
export const getAvailableProductV2 = (data) => {
  return dyrequest({
    url: `${MARKETING}activity/v1/query_available_product_v2`,
    method: "post",
    paramete: {
      _bid: ECCOMMARKETSHOP
    },
    data: {
      page: data.page || 1,
      pageSize: data.pageSize || data.page_size || data.size || 10,
      business_code: "", // activityToolType==26时 && limit_stock_type === 1 &= OrdinaryTimeBuy  activityToolType==16 || 7时无该参数
      limit_stock_type: 1, // activityToolType==26时 活动类型  0 限时限量购 1普通降价 activityToolType==16 || 7时无该参数
      config_scope: 0, // activityToolType==26时 优惠级别 0sku级 1商品级 activityToolType==16 || 7时无该参数
      activityToolType: data.activityToolType || 16, // 16满减活动 26限时限量购 7优惠券
      activitySubType: {
        // activityToolType==7时
        coupon_sub_type: 3 // 与 推广方式有关 11 达人转属 3涨粉券 {通用优惠券: 1全网推广 6客服专属 23品牌 7自有渠道}
      },
      start_time: 1704444824, //  开始时间 设置的多动时间??
      end_time: 1712220824 // 结束时间
    }
  })
}

// 获取限时限量购有效活动列表
export const getListFlashWithTimeLimit = (data) => {
  return dyrequest({
    url: `${MARKETING}promotion/v1/listFlashWithTimeLimit`,
    method: "get",
    paramete: {
      product_id: data.product_id || "", // 商品ID
      title: data.title || "", // 活动名称
      campaign_status: data.campaign_status || "", // 活动状态 '':全部 1：未开始，2：进行中， 6：处理中，4：已结束，3已失效
      shop_stype: data.shop_stype || "", // 优惠类型 1：一口价， 2：直降价 ，3：打折
      page: data.page || 1,
      pageSize: data.pageSize || data.page_size || data.size || 20,
      _bid: data._bid || ECCOMMARKETSHOP,
      business_code : data.business_code || '' // 活动类型 OrdinaryTimeBuy普通降价促销 RealFlash||'' 限时限量购
    }
  })
}
// 获取限时限量购详情 主要获取内部关联的商品
export const getDetailFlashAndGoods = (data) => {
  if (!data.activity_id) throw new Error("缺少活动ID")
  return dyrequest({
    url: `${MARKETING}promotion/v1/detailFlashAndGoods`,
    method: "get",
    paramete: {
      _bid: data._bid || ECCOMMARKETSHOP,
      filter_unable_product: 0, // 过滤不合格产品
      activity_id: data.activity_id // 活动ID
    }
  })
}

// 新人礼金 首单立减 列表
export const getListNewUserGift = (data) => {
  return dyrequest({
    url: `${MARKETING}union_allowance/v1/list_record`,
    method: "get",
    paramete: {
      apply_status: data.apply_status || 3, // 活动状态 3进行中
      page: data.page || 1,
      page_size: data.pageSize || data.page_size || data.size || 20,
      _bid: data._bid || ECCOMMARKETSHOP
    }
  })
}
// 获取新人礼金详情
export const getDetailNewUserGift = (data) => {
  if (!data.apply_id) throw new Error("缺少活动ID apply_id")
  return dyrequest({
    url: `${MARKETING}union_allowance/v1/get_record_detail`,
    method: "get",
    paramete: {
      apply_id: data.apply_id, // 活动状态 3进行中
      _bid: data._bid || ECCOMMARKETSHOP
    }
  })
}

// 获取拼团列表
export const getPromotionListFlash = (data) => {
  return dyrequest({
    url: `${SHOP}promotion/listFlash`,
    method: "get",
    paramete: {
      campaign_status: 1,
      page: data.page || 1,
      pageSize: data.pageSize || data.page_size || data.size || 20,
      stype: 120,
      _bid: data._bid || ECCOMMARKETSHOP
    }
  })
}

// 获取拼团详情
export const getPromotionDetails = (data) => {
  if (!data.campaign_id) throw new Error("缺少活动ID campaign_id")
  return dyrequest({
    url: `${BYTESHOP}promotion/detailGroupBuy`,
    method: "get",
    paramete: {
      campaign_id: data.campaign_id,
      filter_unable_product: data.filter_unable_product || 0,
      _bid: data._bid || ECCOMMARKETSHOP
    }
  })
}

// 获取详情图

export const getPrettifyFromUri = (data) => {
  return dyrequest({
    url: `/product/prettify/getPrettifyFromUri`,
    method: "get",
    paramete: {
      detail_prettify_uri: data.detail_prettify_uri,
    }
  })
}
// https://fxg.jinritemai.com/product/prettify/getPrettifyFromUri?detail_prettify_uri=detail_prettify_814c21e1fb12f2aeb7e11b29020269c0_1rggJx&appid=1&__token=78400536204520a7ac2282bc935a3c3f&_bid=ffa_goods&_lid=938655666584&verifyFp=verify_ltr6b06k_ReqMskhN_euh6_4IB6_BZ8f_QTfhqhszzo1Y&fp=verify_ltr6b06k_ReqMskhN_euh6_4IB6_BZ8f_QTfhqhszzo1Y&msToken=-8Ixx8foG6C_aQysWjq0GChqks4TM2mUYYnf1KBYRIhP0lQXlbPN8pXub90_95V6gTTOSrCFXCk6Rythyokb7x33p_c2-CgSnwB2zfTkTUrC3CvCC54_pg%3D%3D&a_bogus=xvm0BdhfdkDkgfg65WILfY3qIAN3YmgV0Gi0MDZMXxf3bg39HMPH9exL7NTvQZ6jLT%2FAIe8jy4hbO3xprQCJ0Zwf7Who%2F2CZmLX0teMD5VSe-1WeejumE0hO-ib3SFas57NAxc40y75azYT0AoQr-JI6PDnja3Lk96EtrNqL2oM7

// 获取参加活动的商品列表
export const getPromotionProductList = (data) => {
  return dyrequest({
    url: `marketing/activity/v1/query_available_product_v2`,
    method: "post",
    paramete: {
      _bid: ECCOMMARKETSHOP
    },
    data
  })
}

// 检查链接是否满足活动
export const checkPromotionProductList = (data) => {
  return dyrequest({
    url: `marketing/promotion/v1/check_promotion_validation`,
    method: "post",
    paramete: {
      _bid: ECCOMMARKETSHOP
    },
    data
  })
}

// 获取sku列表
export const getSkuList = (data) => {
  return dyrequest({
    url: `marketing/promotion/v1/batch_query_sku_list_v2`,
    method: "post",
    paramete: {
      _bid: ECCOMMARKETSHOP
    },
    data
  })
}

// 创建活动
export const createPromotion = (data) => {
  return dyrequest({
    url: `marketing/promotion/v1/createFlashAndGoods`,
    method: "post",
    timeout: 120000,
    paramete: {
      _bid: ECCOMMARKETSHOP
    },
    data
  })
}

// 失效活动
export const setFlashStatus = (data) => {
  return dyrequest({
    url: `marketing/promotion/v1/setFlashStatus`,
    method: "post",
    paramete: {
      _bid: ECCOMMARKETSHOP
    },
    data
  })
}

// 获取短标题
export const getMiniTitle = (data) => {
  return dyrequest({
    url: `product/tproduct/refetchSchema`,
    method: "post",
    paramete: {
      _bid: ECCOMMARKETSHOP,
      action: 'short_name_ai_gen'
    },
    data
  })
}